<?php

class benchmarkPlugin extends Yaf_Plugin_Abstract {

    public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
        Yaf_Registry::set('benchmark_start', microtime(true));
    }

    public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
        $start = Yaf_Registry::get('benchmark_start');
        Yaf_Registry::del('benchmark_start');

        $time = round(microtime(true) - (float)$start, 5);
        if ($time > 1)
        {
            Log::out($request->getRequestUri() . ':' . $time . ':' . (memory_get_usage(true) / 1024) . 'kb', 'benchmark');
        }
    }

}
